package com.hgxd.mc.utils;

import java.util.ArrayList;
import java.util.List;

public class HexStrTransUtil {

    /**
     * 16进制转化为浮点数
     *
     * @param hexStrList
     * @return
     */
    public static List<Float> HexStrToFloat(List<String> hexStrList) {
        List<Float> floatList = new ArrayList<>();

        for (String hexStr : hexStrList) {
            long longValue = Long.parseLong(hexStr, 16);
            float v = Float.intBitsToFloat((int) longValue);
//            DecimalFormat decimalFormat = new DecimalFormat("0.00");
            floatList.add(v);
        }

        return floatList;
    }

    /**
     * 16进制转化为ASCII
     *
     * @param hexStrList
     * @return
     */
    public static List<String> HexStrToASCII(List<String> hexStrList) {

        List<String> listASCII = new ArrayList<>();
        for (String hexStr : hexStrList) {
            StringBuilder output = new StringBuilder("");
            for (int i = 0; i < hexStr.length(); i += 2) {
                String str = hexStr.substring(i, i + 2);
                output.append((char) Integer.parseInt(str, 16));
            }
            listASCII.add(output.toString());
        }

        return listASCII;
    }
}
